import qs from 'qs'

// 引入mockjs
const Mock =require('mockjs')

 const Random = Mock.Random

// 模拟登陆接口
Mock.mock("/Login","post",(req) =>{
  let item = qs.parse(req);
  var obj = JSON.parse(item.body)
  let username = obj.username
  let password = obj.password
  if(username === 'admin' && password === '123456'){
    return {
      'code':'000',
      'msg':'登陆成功',
      'data':{
        'orgCode':'35002',
        'token':'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoiYWRtaW4iLCJvcmdDb2RlIjoiMzUwMDAiLCJkZXB0Q29kZSI6IjM1MDAwIiwiYXVkIjoiYWRtaW4iLCJpc3MiOiJhZG1pbiIsImV4cCI6MTU5MzUzNTU5OH0.0pJAojRtT5lx6PS2gH_Q9BmBxeNlgBL37ABX22HyDlebbr66cCjVYZ0v0zbLO_9241FX9-FZpCkEqE98MQOyWw',
      }
    }
  }else{
    return {
      'code':'999',
      'msg':'登陆失败'
    }
  }
})

// 用户列表接口
Mock.mock("/user/userinfo", "get", {
  "users|1000": [
    {
        "id|+1": 1,
        name: "@cname",
        identity: '@id()', //得到随机的id,对象
        email: '@email()', //email
        phone:'22222222222',
        status:'管理员',
        state: true
    },
  ],
});

//用户折线图接口
Mock.mock("/charts", "get", {
      'array1|12': [
        () => Random.integer(0, 99)
      ],
      'array2|12': [
        () => Random.integer(0, 99)
      ],    
});

//模拟商品信息接口

Mock.mock("/commodity", "get", {
  "users|1000": [
    {
        "id|+1": 1,
        classify: "@ctitle(50)",   //商品信息 随机十个汉字
        identity: '@id()', 
        name: '@cname()', 
        category:'@ctitle(4)',
        status:'@date'
    },
  ],
});

// 模拟权限管理接口

Mock.mock("/jurisdiction", "get", {
  "users|1000": [
    {
      "id|+1": 1,
      name: "@cname()",   //商品信息 随机十个汉字
      identity: '@id()',
      date:'@date',
      role: '@ctitle(4)', 
      category:'@ctitle(4)'
      
    },
  ],
});

// 模拟订单管理接口

Mock.mock("/order", "get", {
  "users|1000": [
    {
        "id|+1": 1,
        classify: "@natural(1000000000,9999999999)",   //商品信息 随机十个汉字
        identity: '@id()', 
        name1: '@cname()', 
        name2:'@cname()',
        date:'@date',
        result:'@ctitle(2)'
    },
  ],
});